package cn.e4j.modular.api.controller;

import cn.e4j.core.dto.impl.Dto;
import cn.e4j.core.dto.requestDtoResolver.DtoParam;
import cn.e4j.core.dto.requestDtoResolver.DtoWapper;
import cn.e4j.core.reqres.response.ResponseData;
import cn.e4j.modular.api.service.BfcglService;
import cn.e4j.modular.api.service.XsfxService;
import cn.e4j.modular.api.util.ControllerSupport;
import cn.e4j.modular.system.entity.SysUser;
import cn.e4j.modular.system.service.impl.SystemServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.List;

/**
 * 销售分析
 */
@RestController
@RequestMapping("api/wx/xsfx")
public class XsfxController extends ControllerSupport {

    @Autowired
    SystemServiceImpl systemService;

    @Autowired
    XsfxService xsfxService;

    /**
     * 获取非商机拜访记录审核
     *
     * @return
     */
    @RequestMapping(value = "getInfo")
    public ResponseData getInfo(@DtoParam DtoWapper wapper) {
        Dto inDto = wapper.getDto();
        SysUser currentUser = wapper.getSysUser();
        List<Dto> result;

        try {
            inDto.put("USERID", currentUser.getID());

            //上下级权限
            Dto sys003 = systemService.getSys003(currentUser);
            List<Dto> listOrg = (List<Dto>) sys003.get("ORGS");
            inDto.put("ORGS", listOrg);

            Dto sys004 = systemService.getSys004(currentUser, listOrg);
            inDto.put("YWY",sys004.get("YWY"));

            result = xsfxService.getInfo(inDto);
        } catch (Exception e) {
            e.printStackTrace();
            return ERROR;
        }
        return SUCCESS(result);
    }
}
